package com.guli.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guli.commonUtils.R;
import com.guli.eduService.entity.EduCourse;
import com.guli.eduService.entity.EduTeacher;
import com.guli.eduService.service.impl.EduCourseServiceImpl;
import com.guli.eduService.service.impl.EduTeacherServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zxc
 * @date 2023/04/11 11:23
 **/
@Api(description = "查询前台系统首页的课程和讲师数据")
@RestController
@ResponseBody
//@CrossOrigin // 解决跨域问题
@RequestMapping("/eduService/index")
public class IndexController {
    @Autowired
    private EduTeacherServiceImpl teacherService;

    @Autowired
    private EduCourseServiceImpl courseService;

    @ApiOperation(value = "查询前台首页的课程和讲师数据")
    @GetMapping("queryIndexInfo/{courseNum}/{teacherNum}")
    public R queryIndexCourseAndTeacherInfo(
            @ApiParam(name = "courseNum" , value = "查询课程数",required = true)
            @PathVariable String courseNum ,
            @ApiParam(name = "teacherNum" , value = "查询讲师数" ,required = true)
            @PathVariable String teacherNum){
        // 1.根据特定排序规则，查询指定数量的前若干个课程信息;
        List<EduCourse> indexCourseInfo = courseService.queryByCourseNum(courseNum);
        // 2.根据特定排序规则，查询指定数量的前若干个讲师信息
        List<EduTeacher> indexTeacherInfo = teacherService.queryByTeacherNum(teacherNum);

        Map<String , Object> map = new HashMap<>();
        map.put("indexCourseInfo" , indexCourseInfo);
        map.put("indexTeacherInfo" , indexTeacherInfo);
        return R.ok().data(map);
    }
}
